package br.com.persistence;

import java.util.HashMap;

import android.database.Cursor;

public class Form {

	static final int[] EDIT_TEXT_ARRAY_ID = null;
	static final int[] CHECK_BOX_ARRAY_ID = null;
	static final int[] RADIO_BUTTON_ARRAY_ID = null;
	long id;
	private String sem = "Sem resposta";
	
	private HashMap<String,String> formMap = new HashMap<String, String>(); 
	private HashMap<String,String> editTextMap = new HashMap<String, String>(); 
	private HashMap<String,String> checkBoxMap = new HashMap<String, String>(); 
	private HashMap<String,String> radioButtonMap = new HashMap<String, String>();
	
//	public static final int[] EDIT_TEXT_ARRAY_ID = {
//			R.id.editNome,R.id.editMail,R.id.editIdade,R.id.editSurfaQtoTmpo,
//			R.id.editComoSaberOndas,R.id.editSatisfeitoBoletinsSenao,
//			R.id.editContarBoletimAmigosSenao,R.id.editMelhorForma,
//			R.id.editAplicativosEsporteSesim,R.id.editFaltaAplicativoSurf,
//			R.id.editSugestao
//	};
//	
//	public static final int[] CHECK_BOX_ARRAY_ID = {
//			R.id.cboxAcessaPc,R.id.cboxAcessaNet,R.id.cboxAcessaSmart,R.id.cboxAcessaTablet,
//			R.id.cboxAcessaOutro,R.id.cboxMaisAcessaPc,R.id.cboxMaisAcessaNet,
//			R.id.cboxMaisAcessaSmart,R.id.cboxMaisAcessaTablet,R.id.cboxMaisAcessaOutro
//	};
//
//	public static final int[] RADIO_BUTTON_ARRAY_ID = {
//			R.id.radioSurfaSim,R.id.radioSurfaNao,R.id.radioCincoMaisSemana,
//			R.id.radioTresQuatroSemana,R.id.radioUmDoisSemana,
//			R.id.radioDoisTresMes,R.id.radioUmMes,R.id.radioSoVerao,
//			R.id.radioSatisfeitoBoletinsSim,R.id.radioSatisfeitoBoletinsNao,
//			R.id.radioContarBoletimAmigosSim,R.id.radioContarBoletimAmigosNao,
//			R.id.radioAplicativosNosDispositivosSim,R.id.radioAplicativosNosDispositivosNao,
//			R.id.radioAplicativosEsporteSim,R.id.radioAplicativosEsporteNao
//	};
	
	public Form(){};
	
	public Form(Cursor cursor) {
		
		this.id = cursor.getLong(cursor.getColumnIndex(OpenHelper.COLUMN_ID));
		
		foreachMapPut(cursor, EDIT_TEXT_ARRAY_ID, editTextMap);
		foreachMapPut(cursor, CHECK_BOX_ARRAY_ID, checkBoxMap);
		foreachMapPut(cursor, RADIO_BUTTON_ARRAY_ID, radioButtonMap);
		
		formMapSet();
	}

	private void foreachMapPut(Cursor cursor, int[] arrayId, HashMap<String, String> map){
		
		for (int id : arrayId) {
			String key = OpenHelper.COLUMN_PREFIX + id;
			String value = cursor.getString(cursor.getColumnIndex(key));
			map.put(key, value);
		}
		
	}
	
	public long getId() {
		return id;
	}
	
	public HashMap<String, String> getformMap() {
		return formMap;
	}
	
	public HashMap<String, String> getEditTextMap() {
		return editTextMap;
	}

	public HashMap<String, String> getCheckBoxMap() {
		return checkBoxMap;
	}

	public HashMap<String, String> getRadioButtonMap() {
		return radioButtonMap;
	}
	
	public void formMapSet(){
		formMap.putAll(editTextMap);
		formMap.putAll(checkBoxMap);
		formMap.putAll(radioButtonMap);
	}
	
	@Override
	public String toString() {
		String pre = OpenHelper.COLUMN_PREFIX;
		String res = "";
//		res += "Nome:" + formMap.get(pre+R.id.editNome)+"\n";
//		res += "Email:" + formMap.get(pre+R.id.editMail)+"\n";
//		res += "Idade:" + formMap.get(pre+R.id.editIdade)+"\n";
//		res += "vc Surfa? " + formMap.get(pre+R.id.radioSurfaSim)+"\n";
//		res += "vc Surfa? " + getRadioSimNao(pre+R.id.radioSurfaSim, pre+R.id.radioSurfaNao, formMap)+"\n";
//		res += "se sim qto tmpo Surfa? " + formMap.get(pre+R.id.editSurfaQtoTmpo)+"\n";
//		res += "frequencia praia Surfa? " + getFrequenciaRadio(formMap)+"\n";
//		res += "como saber ondas? " + formMap.get(pre+R.id.editComoSaberOndas)+"\n";
//		res += "satisfeito boletins? " + getRadioSimNao(pre+R.id.radioSatisfeitoBoletinsSim, pre+R.id.radioSatisfeitoBoletinsNao, formMap)+"\n";
//		res += "se nao pq? " + formMap.get(pre+R.id.editSatisfeitoBoletinsSenao)+"\n";
//		res += "cataria boletins amigos? " + getRadioSimNao(pre+R.id.radioContarBoletimAmigosSim, pre+R.id.radioContarBoletimAmigosNao, formMap)+"\n";
//		res += "se nao pq? " + formMap.get(pre+R.id.editContarBoletimAmigosSenao)+"\n";
//		res += "melhor forma compartilhar info? " + formMap.get(pre+R.id.editMelhorForma)+"\n";
//		res += "dispositivo usa acessar internet? \n";
//		if(isChecked(pre+R.id.cboxAcessaPc, formMap))
//			res += "pc ";
//		if(isChecked(pre+R.id.cboxAcessaNet, formMap))
//			res += "not ";
//		if(isChecked(pre+R.id.cboxAcessaSmart, formMap))
//			res += "smart ";
//		if(isChecked(pre+R.id.cboxAcessaTablet, formMap))
//			res += "tablet ";
//		if(isChecked(pre+R.id.cboxAcessaOutro, formMap))
//			res += "outro ";
//		
//		res += "dispositivo MAIS usa acessar internet? \n";
//		if(isChecked(pre+R.id.cboxMaisAcessaPc, formMap))
//			res += "pc ";
//		if(isChecked(pre+R.id.cboxMaisAcessaNet, formMap))
//			res += "not ";
//		if(isChecked(pre+R.id.cboxMaisAcessaSmart, formMap))
//			res += "smart ";
//		if(isChecked(pre+R.id.cboxMaisAcessaTablet, formMap))
//			res += "tablet ";
//		if(isChecked(pre+R.id.cboxMaisAcessaOutro, formMap))
//			res += "outro ";
//		
//		res += "costuma usar aplicativos? " + getRadioSimNao(pre+R.id.radioAplicativosNosDispositivosSim, pre+R.id.radioAplicativosNosDispositivosNao, formMap)+"\n";
//		res += "usa app esporte? " + getRadioSimNao(pre+R.id.radioAplicativosEsporteSim, pre+R.id.radioAplicativosEsporteNao, formMap)+"\n";
//		res += "se sim pq? " + formMap.get(pre+R.id.editAplicativosEsporteSesim)+"\n";
//		res += "sente falta? " + formMap.get(pre+R.id.editFaltaAplicativoSurf)+"\n";
//		res += "sugestao " + formMap.get(pre+R.id.editSugestao)+"\n";
		
		return res;
	}
	
	private String getFrequenciaRadio(HashMap<String, String> formMap){
		String pre = OpenHelper.COLUMN_PREFIX;
		
//		if(formMap.get(pre+ R.id.radioCincoMaisSemana).equals("true"))
//			return "5+ semana";
//		else if(formMap.get(pre+ R.id.radioTresQuatroSemana).equals("true"))
//			return "3-4x semana";
//		else if(formMap.get(pre+ R.id.radioUmDoisSemana).equals("true"))
//			return "1-2x semana";
//		else if(formMap.get(pre+ R.id.radioDoisTresMes).equals("true"))
//			return "2-3x mes";
//		else if(formMap.get(pre+ R.id.radioUmMes).equals("true"))
//			return "1x mes";
//		else if(formMap.get(pre+ R.id.radioSoVerao).equals("true"))
//			return "so no verao";
//		else
			return sem;
	}
	
	private boolean isChecked(String id,HashMap<String, String> formMap){
		if(formMap.get(id).equals("true")){
			return true;
		}
		else return false;
	}
	private String getRadioSimNao(String sim, String nao, HashMap<String, String> formMap){

		if(formMap.get(sim).equals("true"))
			return "Sim";
		else if(formMap.get(nao).equals("true"))
			return "Nao";
		else
			return sem;
	}
}
